		TITLE	STORESEQ - Copyright (c) SLR Systems 1994

		INCLUDE MACROS

		PUBLIC	STORE_EAXECX_EDXEBX_RANDOM,STORE_EAXECX_EDX_SEQ


		.DATA

		EXTERNDEF	OPTI_STOSD_SIZE:DWORD


		.CODE	ROOT_TEXT

		externdef	_checkpoint:proc
		EXTERNDEF	GET_NEW_LOG_BLK:PROC,ERR_ABORT:PROC


STORE_EAXECX_EDXEBX_RANDOM	PROC
		;
		;ESI IS SOURCE STRING
		;ECX IS BYTE COUNT TO WRITE
		;EBX IS DATA-TYPE STRUCTURE TO USE
		;EDI IS DESTINATION
		;
		;EAX IS SOURCE STRING
		;ECX IS BYTE COUNT TO WRITE
		;EDX IS DATA-TYPE STRUCTURE
		;EBX IS TARGET ADDRESS
		;
		;STORE NEW HIGH FIRST
		;
		ASSUME	EDX:PTR SEQ_STRUCT

		PUSHM	EDI,EBX

		PUSH	ESI
		LEA	ESI,[EBX+ECX]

		MOV	EDI,[EDX]._SEQ_PTR

		CMP	EDI,ESI
		JAE	SDBS_1

		MOV	[EDX]._SEQ_PTR,ESI
		JMP	SDBS_1

STORE_EAXECX_EDXEBX_RANDOM	ENDP


STORE_EAXECX_EDX_SEQ	PROC
		;
		;EAX IS SOURCE STRING
		;ECX IS BYTE COUNT TO WRITE
		;EDX IS DATA-TYPE STRUCTURE TO USE, SEQ_STRUCT*
		;
		PUSHM	EDI,EBX

		MOV	EBX,[EDX]._SEQ_PTR
		MOV	EDI,ECX

		ADD	EDI,EBX
		PUSH	ESI

		MOV	[EDX]._SEQ_PTR,EDI
SDBS_1::
		MOV	EDI,EBX

		SHR	EDI,16-PAGE_SHIFT
		AND	EBX,PAGE_SIZE-1

		MOV	ESI,EAX
		MOV	EAX,PAGE_SIZE

; The size is set by the size of _SEQ_TABLE[] in common/macros.h and common/macros
cmp EDI,SEQ_TABLE_MAX
jb L100$
push EDI
call _checkpoint
add ESP,4
hlt
L100$:
		LEA	EDX,[EDX+EDI*4]._SEQ_TABLE
		SUB	EAX,EBX				;BYTES LEFT THIS BLOCK

		ASSUME	EDX:NOTHING

		CMP	EAX,ECX
		MOV	EDI,[EDX]

		JC	SDBS_TWO			;NOPE, NEED TWO
SDBS_TWO_1:
		TEST	EDI,EDI
		JZ	L4$
L1$:
		ADD	EDI,EBX
L2$:
		OPTI_MOVSB

		POPM	ESI,EBX,EDI

		RET

L4$:
		MOV	EDI,EBX
		CALL	GET_NEW_LOG_BLK

		MOV	[EDX],EAX
		ADD	EDI,EAX

		GETT	BL,STORE_DSSICX_USE_ZERO

		OR	BL,BL
		JZ	L2$

		PUSHM	EDI,ECX

		MOV	EDI,EAX
		MOV	ECX,OPTI_STOSD_SIZE

		XOR	EAX,EAX

		REP	STOSD

		POPM	ECX,EDI

		JMP	L2$

SDBS_TWO:
		;
		;OOPS, CROSSES A 16K BLOCK BOUNDARY...	DO TWO MOVES
		;
		CALL	SDBS_TWO_PROC
		JMP	SDBS_TWO_1

STORE_EAXECX_EDX_SEQ	ENDP


SDBS_TWO_PROC	PROC	NEAR
		;
		;
		;
		SUB	ECX,EAX
		TEST	EDI,EDI

		PUSH	ECX
		JZ	L4$

		MOV	ECX,EAX
		ADD	EDI,EBX
L1$:
		ADD	EDX,4
		XOR	EBX,EBX

		OPTI_MOVSB

		POP	ECX
		MOV	EDI,[EDX]

		RET

L4$:
		MOV	ECX,EAX
		CALL	GET_NEW_LOG_BLK

		MOV	[EDX],EAX
		LEA	EDI,[EAX+EBX]

		GETT	BL,STORE_DSSICX_USE_ZERO

		OR	BL,BL
		JZ	L1$

		PUSHM	EDI,ECX

		MOV	EDI,EAX
		MOV	ECX,OPTI_STOSD_SIZE

		XOR	EAX,EAX

		REP	STOSD

		POPM	ECX,EDI

		JMP	L1$

SDBS_TWO_PROC	ENDP


		END

